package com.hx.shardingsphere.rws.controller;


import com.hx.shardingsphere.common.mapper.OrderMapper;
import com.hx.shardingsphere.common.model.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jxlgcmh
 * @date 2020-05-08 18:36
 * @description
 */
@RestController
public class MyController {

    @Autowired
    private OrderMapper orderMapper;

    @RequestMapping("/insert/{id}")
    public String insert(@PathVariable Integer id){
        Order order = new Order();
        order.setUserId(id);
        order.setOrderId(id);
        int result = orderMapper.insert(order);
        return "succes";
    }


    @RequestMapping("/query/{orderId}")
    public Order query(@PathVariable Integer orderId){
//        HintManager.getInstance().setMasterRouteOnly();
        Order order = orderMapper.selectById(orderId);
        if (order != null) {
            return order;
        }
        else {
            Order fail = new Order();
            fail.setOrderId(-1);
            fail.setUserId(-1);
            return fail;
        }
    }

}
